// import Vue from "vue";
// import VueRouter from "vue-router";
import routes from "./routes";

Vue.use(VueRouter);

let push = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    push.call(this, location, resolve, reject);
  } else {
    push.call(
      this,
      location, 
      () => {},
      () => {}
    );
  }
};

let router =  new VueRouter({
  mode: "hash",
  routes,
  //设置滚动条滚动行为---A->B,可以操作滚动条行为
  //当路由跳转的时候会执行一次
  scrollBehavior(to, from, savePosition) {
    //savedPosition:按返回|前进按钮对象
    //想跳转过去的路由对象   对象
    //从那个路由过来的      对象
    if (savePosition) {
      return savePosition;
    } else {
      return { y: 0 };
    }
  },
});

export default router;
